package Solution;

import java.util.LinkedList;

import moverules.PlayerMove;

import exceptions.NotYetImplementedException;
import board.Board;
import board.Cord;
import board.Move;
import board.MoveImpl;
import board.Board.CellType;
import board.VisitedCellHelper;

public class SolveHW1 implements SolutionFinder {

	private static PlayerMove playerMoveRule = new PlayerMove();
	
	@Override
	public String FindSolution(Board board) 
	{
		
		Cord player = board.getPlayer();
		
		Move playerBegin = new MoveImpl( player.getX() , player.getY(), null, "");
		
		LinkedList<Move> queue = new LinkedList<Move>();
		
		queue.add(playerBegin);
		
		VisitedCellHelper visited = board.getVisitedBoardHelper();
		
		while(true)
		{

			Move currentMove = queue.removeFirst(); // BFS
			
			System.out.println( currentMove.getX() +":"+ currentMove.getY() );
			
			if ( visited.unisitedCell(currentMove) )
			{
				visited.registerCellAsVisited(currentMove);
				
				if ( ( board.getCellType(currentMove) == CellType.GoalSquare ) ||
						( board.getCellType(currentMove) == CellType.PlayerOnGoalSquare ) )
						{
							return currentMove.getPathToThis();
						}
						
						for ( Move m : board.getLegalMoves(currentMove, playerMoveRule) )
						{
							queue.addLast( m );
						}
				
			}
			else
			{
				// Do nothing
			}
		
			
		}
		
	}
	
//	public String DFS( Board board, Move move, String currentPath, VisitedCellHelper visited )
//	{
//		if ( !visited.unisitedCell(move) )
//		{
//			return null;
//		}
//		else
//		{
//			visited.registerCellAsVisited(move);
//		}
//		
//		if ( ( board.getCellType(move) == CellType.GoalSquare ) ||
//		( board.getCellType(move) == CellType.PlayerOnGoalSquare ) )
//		{
//			return currentPath;
//		}
//		
//		for ( Move m : board.getLegalMoves(move, playerMoveRule) )
//		{
//			DFS(board, m, currentPath+m.getDirectionToThis().toString(), visited);
//		}
//		
//	}

}
